<?php
/// Copyright (c) 2004-2007, Cain Chen / Hina :: 工程幼稚園
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)

/// Sitemap build and notify, read more on http://www.sitemaps.org/protocol.php
/// Sitemap XML format:
/// The Sitemap protocol format consists of XML tags. All data values in a Sitemap must be entity-escaped. The file itself must be UTF-8 encoded.

/// Your Sitemap file must be UTF-8 encoded (you can generally do this when you save the file). As with all XML files, any data values (including URLs) must use entity escape codes for the characters listed in the table below.
//////////////////////////////////////
///    Character   /// Escape Code ///
/// Ampersand    & /// &amp;       ///
/// Single Quote ' /// &apos;      ///
/// Double Quote " /// &quot;      ///
/// Greater Than > /// &gt;        ///
/// Less Than    < /// &lt;        ///
//////////////////////////////////////

/// In addition, all URLs (including the URL of your Sitemap) must be URL-escaped and encoded for readability by the web server on which they are located. However, if you are using any sort of script, tool, or log file to generate your URLs (anything except typing them in by hand), this is usually already done for you. Please check to make sure that your URLs follow the RFC-3986 standard for URIs, the RFC-3987 standard for IRIs, and the XML standard.

/// This plugin will build the sitemap file with $blogid, for example: sitemap_1.xml and sitemap_1.xml.gz. And create a index file called sitemap.xml that using Sitemap Index file rule(http://www.sitemaps.org/protocol.php#index) to include users's single sitemap file.

/// Sample Sitemap index files with blogid, this file called "sitemap.xml"
/*************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <sitemap>
      <loc>http://www.example.com/blog/sitemap_1.xml.gz</loc>
      <lastmod>2004-10-01T18:23:17+00:00</lastmod>
   </sitemap>
   <sitemap>
      <loc>http://www.example.com/blog/sitemap_2.xml.gz</loc>
      <lastmod>2005-01-01</lastmod>
   </sitemap>
</sitemapindex>
*************************************************************************************/
/// Sample XML Sitemap (single file), this file called "sitemap_1.xml" and it will be zipped to .gz file using gzip.
/************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/blog/</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset>
*************************************************************************************/


if (!defined('ROOT')) {
	header('HTTP/1.1 403 Forbidden');
	header("Connection: close");
	exit;
}

global $globalSitemapFile, $sitemapprefix, $notifyGoogleCheck, $notifyYahooCheck, $notifyMSNCheck, $notifyASKCheck, $notifyBaiduCheck;

requireComponent( "Textcube.Function.misc" );

$sitemapprefix = "sitemap_";
$globalSitemapFile = "sitemap.xml";
$notifyGoogleCheck = false;
$notifyYahooCheck = false;
$notifyMSNCheck = false;
$notifyASKCheck = false;
$notifyBaiduCheck = false;

if(isset($__ts)) unset($__ts);
$__ts = array();

global $blog, $service, $__ts;
# Locale language file support, defualt is en-us.php
if (!isset($blog['blogLanguage'])) {
	$blog['blogLanguage'] = $service['language'];
}
// Locale language file support.
switch($blog['blogLanguage']) {
	case "zh-TW":
	case "zh-CN":
		$languageFile = 'lang/'.$blog['blogLanguage'].'.php';
	break;
	default:
		$languageFile = "";
}
if(!empty($languageFile)) { include ($languageFile); }

function sitemap_buildonchange()
{
	requireModel('common.setting');
	
	header('Content-Type: text/xml; charset=utf-8');
	if( !Acl::check( array("group.administrators") ) ) {
		getRespondResultPage(0);
		return;
	}
	if( setServiceSetting("SitemapBuildonChange", (empty($_GET['mode']) ? 0 : 1) ) ) {
		getRespondResultPage(1);
	} else {
		getRespondResultPage(0);
	}
}

function sitemap_notification()
{
	requireModel('common.setting');
	
	header('Content-Type: text/xml; charset=utf-8');
	if( !Acl::check( array("group.administrators") ) ) {
		getRespondResultPage(0);
		return;
	}
	if (isset($_GET) && $_GET['mode']=='google' && setServiceSetting( "SitemapNotifyGoogle", (($_GET['setup']==0) ? 0 : 1) ) )
	{
		getRespondResultPage(1);
	} elseif (isset($_GET) && $_GET['mode']=='yahoo' && setServiceSetting( "SitemapNotifyYahoo", (($_GET['setup']==0) ? 0 : 1) ) )
	{
		getRespondResultPage(1);
	} elseif (isset($_GET) && $_GET['mode']=='msn' && setServiceSetting( "SitemapNotifyMSN", (($_GET['setup']==0) ? 0 : 1) ) )
	{
		getRespondResultPage(1);
	} elseif (isset($_GET) && $_GET['mode']=='ask' && setServiceSetting( "SitemapNotifyASK", (($_GET['setup']==0) ? 0 : 1) ) )
	{
		getRespondResultPage(1);
	/* Baidu do not support sitemap
	} elseif (isset($_GET) && $_GET['mode']=='baidu' && setServiceSetting( "SitemapNotifyBaidu", (($_GET['setup']) ? 0 : 1) ) )
	{
		getRespondResultPage(1);
	*/
	} else {
		getRespondResultPage(0);
	}
}

function getMicrotime()
{
    list($usec, $sec) = explode(' ', microtime());
    return ((double)$usec + (double)$sec);
}

function sitemap_buildindex() {
	global $blog, $service, $database, $pluginURL, $hostURL, $blogid, $blogURL, $SERVER_ABS_PATH, $sitemapprefix, $globalSitemapFile, $notifyGoogleCheck, $notifyYahooCheck, $notifyMSNCheck, $notifyASKCheck, $notifyBaiduCheck;
	requireModel('common.setting');
	
	$userid = array();
	$sitemapIndex = "";
	$rows = DBQuery::queryAll("select userid from {$database['prefix']}Users");
	foreach( $rows as $row ) {
		$userid[] = $row["userid"];
	}
	$runStart = getMicrotime();
	ob_start();
	echo '<?xml version="1.0" encoding="UTF-8"?>', CRLF;
	echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', CRLF;
	foreach ($userid as $fileIndex) {
		if (file_exists(ROOT."/cache/sitemap/".$sitemapprefix.$fileIndex.'.xml.gz')) {
			$filemtime = date("Y-m-d", filemtime(ROOT."/cache/sitemap/".$sitemapprefix.$fileIndex.'.xml.gz'));
			echo '   <sitemap>', CRLF;
			echo '      <loc>', $hostURL, $service['path'],'/cache/sitemap/',$sitemapprefix, $fileIndex, '.xml.gz</loc>', CRLF;
			echo '      <lastmod>', $filemtime, '</lastmod>', CRLF;
			echo '   </sitemap>', CRLF;
		}
	}
	echo '</sitemapindex>', CRLF;
	$sitemapIndex = ob_get_contents();
	ob_end_clean();

	$rootIndexFile = ROOT.'/cache/sitemap/'.$globalSitemapFile;
	if (file_exists($rootIndexFile)) @unlink($rootIndexFile);
	$fileHandle = fopen($rootIndexFile, 'w');
	if (fwrite($fileHandle, $sitemapIndex)) {
		fclose($fileHandle);
		@chmod($rootIndexFile, 0666);
	}

	/// notify google and yahoo!
	$notifyGoogle = getServiceSetting( "SitemapNotifyGoogle", "") == 0 ? false : true;
	$notifyYahoo = getServiceSetting( "SitemapNotifyYahoo", "") == 0 ? false : true;
	$notifyMSN = getServiceSetting( "SitemapNotifyMSN", "") == 0 ? false : true;
	$notifyASK = getServiceSetting( "SitemapNotifyASK", "") == 0 ? false : true;
//	$notifyBaidu = getServiceSetting( "SitemapNotifyBaidu", "") == 0 ? false : true;
	$notifyURL = urlencode($hostURL.$service['path'].'/cache/sitemap/'.$globalSitemapFile);
	/// debug mode use reponse value
	$reponse = "";
	if ($notifyGoogle) {
		if(function_exists('curl_init')) {
			/// use curl module
			$url = "http://www.google.com/webmasters/tools/ping?sitemap=".$notifyURL;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$reponse .= @curl_exec($ch);
			if (!curl_errno($ch)) $notifyGoogleCheck = true;
			curl_close($ch);
		} else {
			/// use socket
			$host = "www.google.com";
			$port = "80";
			$getData = "GET /webmasters/tools/ping?sitemap=".$notifyURL." HTTP/1.0\r\n\r\n";
			if( true == ($socket = @socket_create(AF_INET, SOCK_STREAM, 0))) {
				@socket_connect ( $socket, $host, $port );
				@socket_write ( $socket, $getData, strlen($getData) );
				if( substr(@socket_read( $socket, 15 ), 9, 3)=="200") $notifyGoogleCheck = true;
				socket_close($socket);
			}
		}
	}
	if ($notifyYahoo) {
		if(function_exists('curl_init')) {
			/// use curl module
			$url = "http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=".$notifyURL;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$reponse .= @curl_exec($ch);
			if (!curl_errno($ch)) $notifyYahooCheck = true;
			curl_close($ch);
		} else {
			/// use socket
			$host = "search.yahooapis.com";
			$port = "80";
			$getData = "GET /SiteExplorerService/V1/ping?sitemap=".$notifyURL." HTTP/1.0\r\n\r\n";
			if( true == ($socket = @socket_create(AF_INET, SOCK_STREAM, 0))) {
				@socket_connect ( $socket, $host, $port );
				@socket_write ( $socket, $getData, strlen($getData) );
				if( substr(@socket_read( $socket, 15 ), 9, 3)=="200") $notifyYahooCheck = true;
				socket_close($socket);
			}
		}
	}
	if ($notifyMSN) {
		if(function_exists('curl_init')) {
			/// use curl module
			$url = "http://webmaster.live.com/ping.aspx?sitemap=".$notifyURL;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$reponse .= curl_exec($ch);
			if (!curl_errno($ch)) $notifyMSNCheck = true;
			curl_close($ch);
		} else {
			/// use socket
			$host = "webmaster.live.com";
			$port = "80";
			$getData = "GET /ping.aspx?sitemap=".$notifyURL." HTTP/1.0\r\n\r\n";
			if( true == ($socket = @socket_create(AF_INET, SOCK_STREAM, 0))) {
				@socket_connect ( $socket, $host, $port );
				@socket_write ( $socket, $getData, strlen($getData) );
				if( substr(@socket_read( $socket, 15 ), 9, 3)=="200") $notifyMSNCheck = true;
				socket_close($socket);
			}
		}
	}
	if ($notifyASK) {
		if(function_exists('curl_init')) {
			/// use curl module
			$url = "http://submissions.ask.com/ping?sitemap=".$notifyURL;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$reponse .= curl_exec($ch);
			if (!curl_errno($ch)) $notifyASKCheck = true;
			curl_close($ch);
		} else {
			/// use socket
			$host = "submissions.ask.com";
			$port = "80";
			$getData = "GET /ping?sitemap=".$notifyURL." HTTP/1.0\r\n\r\n";
			if( true == ($socket = @socket_create(AF_INET, SOCK_STREAM, 0))) {
				@socket_connect ( $socket, $host, $port );
				@socket_write ( $socket, $getData, strlen($getData) );
				if( substr(@socket_read( $socket, 15 ), 9, 3)=="200") $notifyASKCheck = true;
				socket_close($socket);
			}
		}
	}	
	return $reponse;
}

function sitemap_rebuildcheck() {
	global $blog, $service, $database, $pluginURL, $hostURL, $blogid, $blogURL, $SERVER_ABS_PATH, $sitemapprefix;
	requireModel('common.setting');
	$owner = getUserId();
	$sitemapSingle = "";
	$sitemapIndex = "";
	$rebuild = false;
	$force = (isset($_GET['force'])) ? true : false;

	if(!is_null(getServiceSetting('TextcubeXMLSitemapAddon'))) {
		$lastModify = getServiceSetting('TextcubeXMLSitemapAddon');
	} else {
		$lastModify = time();
		setServiceSetting('TextcubeXMLSitemapAddon',$lastModify);
	}
	
	/// check directory
	if (!@is_dir(ROOT.'/cache/sitemap')) {
		@mkdir (ROOT.'/cache/sitemap', 0777);
		@chmod (ROOT.'/cache/sitemap', 0777);
	}
	if (!@is_dir(ROOT."/cache/sitemap/{$blogid}")) {
		@mkdir (ROOT."/cache/sitemap/{$blogid}", 0777);
		@chmod (ROOT."/cache/sitemap/{$blogid}", 0777);			
	}
	/// file path setting.
	$cacheFile = ROOT."/cache/sitemap/{$blogid}/".$sitemapprefix.$owner.'.xml';
	$gzcacheFile = $cacheFile.'.gz';
	$rootgzFile = ROOT."/cache/sitemap/".$sitemapprefix.$owner.'.xml.gz';

	/// delete all cache file if expired(5 mins expired).
	if ((time() - $lastModify) > 300 || $force==true) $rebuild = true;
	if(!file_exists($cacheFile) || !file_exists($gzcacheFile) || !file_exists($rootgzFile)) $rebuild = true;
	if(file_exists($cacheFile) && $rebuild==true) @unlink($cacheFile);
	if(file_exists($gzcacheFile) && $rebuild==true) @unlink($gzcacheFile);
	if(file_exists($rootgzFile) && $rebuild==true) @unlink($rootgzFile);	
	if ( $rebuild == true ) {
		sitemap_buildsitemap();
		removeServiceSetting('TextcubeXMLSitemapAddon');
	}
	$sitemapIndex = sitemap_buildindex();
	if ($force) {
		header('Content-Type: text/xml; charset=utf-8');
		getRespondResultPage(1);
	} else {
		return (sitemap_buildindex());
	}
}

function sitemap_lastModify($target) {
	global $blog, $service, $database, $pluginURL, $hostURL, $blogid, $blogURL, $SERVER_ABS_PATH, $sitemapprefix;
	requireModel('common.setting');
	$owner = getUserId();
	/// logout force rebuild sitemap, if entries has modified over 5 mins.
	$buildonchange = misc::getBlogSettingGlobal( "SitemapBuildonChange", "") == 0 ? false : true;

	if(!is_null(getServiceSetting('TextcubeXMLSitemapAddon'))) {
		$lastModify = getServiceSetting('TextcubeXMLSitemapAddon');
	} else {
		$lastModify = time();
		setServiceSetting('TextcubeXMLSitemapAddon',$lastModify);
	}
	
	if ($buildonchange == true || $lastModify - time() > 300) {
		/// file path setting.
		$cacheFile = ROOT."/cache/sitemap/{$blogid}/".$sitemapprefix.$owner.'.xml';
		$gzcacheFile = $cacheFile.'.gz';
		$rootgzFile = ROOT."/cache/sitemap/".$sitemapprefix.$owner.'.xml.gz';
		/// delete all cache file.
		if(file_exists($cacheFile) && $rebuild==true) @unlink($cacheFile);
		if(file_exists($gzcacheFile) && $rebuild==true) @unlink($gzcacheFile);
		if(file_exists($rootgzFile) && $rebuild==true) @unlink($rootgzFile);	
		/// force rebuild sitemap.xml.gz
		$_noreply = sitemap_buildsitemap();
		/// force rebuild sitemap.xml
		$_noreply = sitemap_buildindex();
	}
	
	return $target;
}

function sitemap_buildsitemap() {
	global $suri, $blog, $service, $database, $pluginURL, $hostURL, $blogid, $blogURL, $SERVER_ABS_PATH, $sitemapprefix;
	$sitemapSingle = "";
	$owner = getUserId();
	$userBlogUrl = getBlogURL();
	$cacheFile = ROOT."/cache/sitemap/{$blogid}/".$sitemapprefix.$owner.'.xml';
	$gzcacheFile = $cacheFile.'.gz';
	$rootgzFile = ROOT."/cache/sitemap/".$sitemapprefix.$owner.'.xml.gz';	
	/// xml-sitemap schemas
	ob_start();
	echo '<?xml version="1.0" encoding="UTF-8"?>', CRLF;
	echo '<urlset', CRLF;
	echo '	  xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"', CRLF;
	echo '	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', CRLF;
	echo '	  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9', CRLF;
	echo '			http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">', CRLF, CRLF;
	
	/// build blog root, subroot
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/cover</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/notice</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/tag</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/location</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/keylog</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/guestbook</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	echo '<url>', CRLF;
	echo '  <loc>', $userBlogUrl, '/rss</loc>', CRLF;
	echo '  <priority>0.8</priority>', CRLF;
	echo '  <changefreq>daily</changefreq>', CRLF;
	echo '</url>', CRLF;
	
	/// build notice
	$rows = DBQuery::queryAll("select id, slogan from {$database['prefix']}Entries where category='-2' and visibility>=2 and userid='$owner' and blogid='$blogid' ORDER BY id ASC");
	foreach( $rows as $row ) {
		$permalink = ($blog['useSloganOnPost'])? urlencode($row['slogan']) : $row['id'];
		echo '<url>', CRLF;
		echo '  <loc>', $userBlogUrl, '/notice/', $permalink, '</loc>', CRLF;
		echo '  <priority>0.5</priority>', CRLF;
		echo '  <changefreq>daily</changefreq>', CRLF;
		echo '</url>', CRLF;
	}		
	
	/// build entry
	$rows = DBQuery::queryAll("select id, slogan from {$database['prefix']}Entries where category>=0 and visibility>=2 and userid='$owner' and blogid='$blogid' ORDER BY id ASC");
	foreach( $rows as $row ) {
		$permalink = ($blog['useSloganOnPost'])? 'entry/'.urlencode($row['slogan']) : $row['id'];
		echo '<url>', CRLF;
		echo '  <loc>', $userBlogUrl, '/', $permalink, '</loc>', CRLF;
		echo '  <priority>0.5</priority>', CRLF;
		echo '  <changefreq>daily</changefreq>', CRLF;
		echo '</url>', CRLF;
	}

	echo '</urlset>', CRLF;
	$sitemapSingle = ob_get_contents();
	ob_end_clean();
	
	$fileHandle = fopen($cacheFile, 'w');
	if (fwrite($fileHandle, $sitemapSingle)) {
		fclose($fileHandle);
		@chmod($cacheFile, 0666);
		$zp = @gzopen($gzcacheFile, "w9");
		@gzwrite($zp, $sitemapSingle);
		@gzclose($zp);
		@copy($gzcacheFile, $rootgzFile);
	}
	
	return "";
}

function getRespondResultPage($error){
	if($error==1) {
		print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response>\n<error>0</error>\n</response>");
	} elseif($error==0) {
		print ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response>\n<error>1</error>\n</response>");
	}
	exit;
}

function sitemap_Manage() {
	global $blog, $service, $database, $pluginURL, $hostURL, $blogURL, $blogid, $SERVER_ABS_PATH, $globalSitemapFile, $sitemapprefix, $notifyGoogleCheck, $notifyYahooCheck, $notifyMSNCheck, $notifyASKCheck, $notifyBaiduCheck;
	requireModel('common.setting');
	$owner = getUserId();
	require_once ('lang/pluginLocal.php');
	
	if (substr(file_get_contents(ROOT.'/cache/CHECKUP'), 0, 3) < 1.5) {
		$_text = _t('Alert ::\r\n - This plugin must be Textcube 1.5 or above. \r\n Please update your textcube and try again.');
		$setupAlert = '<script type="text/javascript">alert("'.$_text.'"); history.go(-1);</script>';
		exit;
	}
	# rebuild sitemap
	$runStart = getMicrotime();
	$sitemapIndex = sitemap_rebuildcheck();
	$overTime = sprintf('%01.4f', getMicrotime() - $runStart);
	# confirm the checkbox
	
	$buildonchange = (getServiceSetting("SitemapBuildonChange")==0) ? '' : 'checked="checked"';
	$notifyGoogle = (getServiceSetting("SitemapNotifyGoogle") == 0) ? '' : 'checked="checked"';
	$notifyYahoo = (getServiceSetting("SitemapNotifyYahoo")==0) ? '' : 'checked="checked"';
	$notifyMSN = (getServiceSetting("SitemapNotifyMSN")==0) ? '' : 'checked="checked"';
	$notifyASK = (getServiceSetting("SitemapNotifyASK")==0) ? '' : 'checked="checked"';
	//$notifyBaidu = (getServiceSetting("SitemapNotifyBaidu")==0) ? '' : 'checked="checked"';

	$indexonTime = Timestamp::format5(filemtime(ROOT."/cache/sitemap/".$globalSitemapFile));
	$gzonTime = Timestamp::format5(filemtime(ROOT."/cache/sitemap/{$blogid}/".$sitemapprefix.$owner.'.xml.gz'));
?>
	<style type="text/css" media="screen">
    <!--
    th div {
        text-align: left;
        font-weight: bold;
    }
    .site div {
        text-align: left;
    }
    .site div blockquote {
        margin-left: 2.0em;
    }
    .site ul li {
        line-height: 2.0em;
    }
    ul.status li {
        list-style-type: circle !important;
    }
	span.rebuild-sitemap {
		text-decoration: underline;
		color: #0066CC;
		cursor: pointer;
	}
	li dfn {
		color: #FF0000;
		font-style: normal;
	}
    -->
    </style>

	<script type="text/javascript" language="javascript">
	//<![CDATA[
	function toggle_buildonchange() {
		try {
			var oo = document.getElementById( 'buildonchange' );
			if( ! oo ) {
				return false;
			}
			oo = oo.checked ? "1" : "0";
			var request = new HTTPRequest("GET", "<?php echo $blogURL;?>/plugin/sitemap/buildonchange?mode=" + oo);
			request.onSuccess = function() {
				PM.removeRequest(this);
				PM.showMessage("<?php echo _t('저장되었습니다.');?>", "center", "bottom");
			}
			request.onError = function() {
				PM.removeRequest(this);
				PM.showErrorMessage("<?php echo _t('저장하지 못했습니다.');?>", "center", "bottom");
			}
			request.send("");
		} catch(e) {
		}
	}
	function toggle_notification(target) {
		try {
			var targetId = 'notify'+target;
			var oo = document.getElementById( targetId );
			if( ! oo ) {
				return false;
			}
			oo = oo.checked ? "1" : "0";
			var request = new HTTPRequest("GET", "<?php echo $blogURL;?>/plugin/sitemap/notification?mode=" + target + "&setup=" + oo);
			request.onSuccess = function() {
				PM.removeRequest(this);
				PM.showMessage("<?php echo _t('저장되었습니다.');?>", "center", "bottom");
			}
			request.onError = function() {
				PM.removeRequest(this);
				PM.showErrorMessage("<?php echo _t('저장하지 못했습니다.');?>", "center", "bottom");
			}
			request.send("");
		} catch(e) {
		}
	}
	function toggle_rebuildsitemap() {
		try {
			var request = new HTTPRequest("GET", "<?php echo $blogURL;?>/plugin/sitemap/rebuildsitemap?force=1");
			request.onSuccess = function() {
				PM.removeRequest(this);
				PM.showMessage("<?php echo pluginLang::plfs('Sitemap rebuild completed.');?>", "center", "bottom");
			}
			request.onError = function() {
				PM.removeRequest(this);
				PM.showErrorMessage("<?php echo pluginLang::plfs('Sitemap no need to rebuild.');?>", "center", "bottom");
			}
			request.send("");
		} catch(e) {
		}
	}
	//]]>
	</script>

	<div id="sitemap-status" calss="part">
		<h2 class="caption"><span class="main-text"><?php echo pluginLang::plfs('Status.');?></span></h2>
		<table class="data-inbox" cellspacing="0" cellpadding="0">
            <tbody>
			<tr class="site">
			<td><div><blockquote><ul class="status">
            <li><?php echo pluginLang::plfs('Your sitemap was last built on %1', $indexonTime);?></li>
            <li><?php echo pluginLang::plfs('Your sitemap(zipped, .gz) was last built on %1', $gzonTime);?></li>
            <?php if (!empty($notifyGoogle)) {?><li><?php echo ($notifyGoogleCheck) ? pluginLang::plfs('Google was successfully notified about changes.') : pluginLang::plfs('Google was unsuccessfully notified about changes.');?></li><? };?>
            <?php if (!empty($notifyYahoo)) {?><li><?php echo ($notifyYahooCheck) ? pluginLang::plfs('Yahoo! was successfully notified about changes.') : pluginLang::plfs('Yahoo! was unsuccessfully notified about changes.');?></li><? };?>
            <?php if (!empty($notifyMSN)) {?><li><?php echo ($notifyMSNCheck) ? pluginLang::plfs('MSN was successfully notified about changes.') : pluginLang::plfs('MSN was unsuccessfully notified about changes.');?></li><? };?>
            <?php if (!empty($notifyASK)) {?><li><?php echo ($notifyASKCheck) ? pluginLang::plfs('ASK.com was successfully notified about changes.') : pluginLang::plfs('ASK.com was unsuccessfully notified about changes.');?></li><? };?>
            <!-- Baidu do not support sitemap
            <?php if (!empty($notifyBaidu)) {?><li><?php echo ($notifyBaiduCheck && !empty($notifyBaidu)) ? pluginLang::plfs('Baidu was successfully notified about changes.') : pluginLang::plfs('Baidu was unsuccessfully notified about changes.');?></li><? };?>
            -->
            <li><?php echo pluginLang::plfs('The building process took about %1 seconds to complete.', $overTime);?></li>
            <li><?php echo pluginLang::plfs('If you changed something on your server or blog, your should %1rebuild the sitemap%2 manually.', '<span class="rebuild-sitemap" onclick="toggle_rebuildsitemap();">','</span>');?></li>
			</ul></blockquote></div></td>
			</tr></tbody>
		</table>
	</div>
    <div id="sitemap-basic-options" calss="part">
		<h2 class="caption"><span class="main-text"><?php echo pluginLang::plfs('Basic Options.');?></span></h2>
        <table class="data-inbox" cellspacing="0" cellpadding="0">
            <thead>
            <tr><th><div><?php echo pluginLang::plfs('Building mode:');?></div></th></tr>
            </thead>
            <tbody>
            <tr class="site">
			<td><div><blockquote><ul>
            <li><input id="buildonchange" type="checkbox" name="buildonchange" onclick="toggle_buildonchange();" <?=$buildonchange;?> />&nbsp;<label for="buildonchange"><?php echo pluginLang::plfs('Rebuild sitemap if you change the content of your blog.');?></label></li>
            </ul></blockquote></div></td>
            </tr>
            </tbody>
        </table>
        <table class="data-inbox" cellspacing="0" cellpadding="0">
            <thead>
            <tr><th><div><?php echo pluginLang::plfs('Update notification:');?></div></th></tr>
            </thead>
            <tbody>
            <tr class="site">
			<td><div><blockquote><ul>
            <li><input id="notifygoogle" type="checkbox" name="notifygoogle" onclick="toggle_notification('google');" <?=$notifyGoogle;?> />&nbsp;<label for="notifyGoogle"><?php echo pluginLang::plfs('Notify Google about updates of your blog.');?></label></li>
            <li><input id="notifyyahoo" type="checkbox" name="notifyyahoo" onclick="toggle_notification('yahoo');" <?=$notifyYahoo;?> />&nbsp;<label for="notifyYahoo"><?php echo pluginLang::plfs('Notify Yahoo! about updates of your blog.');?></label></li>
            <li><input id="notifymsn" type="checkbox" name="notifymsn" onclick="toggle_notification('msn');" <?=$notifyMSN;?> />&nbsp;<label for="notifyMSN"><?php echo pluginLang::plfs('Notify MSN about updates of your blog.');?></label></li>
            <li><input id="notifyask" type="checkbox" name="notifyask" onclick="toggle_notification('ask');" <?=$notifyASK;?> />&nbsp;<label for="notifyASK"><?php echo pluginLang::plfs('Notify ASK.com about updates of your blog.');?></label></li>
            <!-- Baidu do not support sitemap
            <li><input id="notifybaidu" type="checkbox" name="notifybaidu" onclick="toggle_notification('baidu');" <?=$notifyBaidu;?> />&nbsp;<label for="notifyBaidu"><?php echo pluginLang::plfs('Notify Baidu about updates of your blog.');?></label></li>
            -->
            </ul></blockquote></div></td>
            </tr>
            </tbody>
		</table>
    </div>
<?php    
}
?>